package com.ruoyi.project.im.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.im.bean.IMAuth;
import com.ruoyi.project.im.bean.IMBaseRes;
import com.ruoyi.project.im.users.domain.Users;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Component
public class CommandLineRunnerImpl implements CommandLineRunner {


    @Override
    public void run(String... args) throws Exception {

        getToken();
    }


    private void getToken(){

        Map<String,Object> map = new HashMap<>();
        map.put("platform",5);
        map.put("userID","openIMAdmin");
        map.put("operationID",getOperationID());
        map.put("secret","tuoyun");
        String jsonString = JSON.toJSONString(map);
        JSONObject result = Http.post(Http.USER_TOKEN,jsonString);
        IMBaseRes baseRes = result.toJavaObject(IMBaseRes.class);
        JSONObject data = JSON.parseObject(baseRes.data.toJSONString());
        Http.openIMAdmin = data.getString("token");

    }

    private String getOperationID() {
        Date date = new Date();
        return date.getTime()+"";
    }


}
